import os
import signal
import subprocess


def run_moveit2():
    process = subprocess.Popen(
        '/bin/bash -c "source install/setup.bash; colcon build; ros2 launch mybot demo.launch.py"',
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        # executable="source install/setup.bash",
        shell = True,
        bufsize = -1,
        preexec_fn = os.setsid,
    )
    return process


def kill_moveit2(process):
    process.terminate()
    process.wait()
    os.killpg(process.pid, signal.SIGTERM)
    # os.killpg(os.getpgid(process.pid), signal.SIGINT)
